<!DOCTYPE html>












  


<html class="theme-next pisces use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2"/>
<meta name="theme-color" content="#222">












<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />






















<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=6.4.0" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=6.4.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=6.4.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=6.4.0">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=6.4.0" color="#222">









<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Pisces',
    version: '6.4.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="ios 端 可参考：https://www.jianshu.com/p/879d28ee74e6趁热打铁吧，把刚才已经完成的友盟统计集成记录下  Android端集成：分下面几部： 步骤 sdk的集成 原生模块的配置 原生交互模块 RN端调用  sdk集成部分友盟sdk下载地址：https://developer.umeng.com/sdk?spm=a211g2.211692.0.0.4cc211">
<meta name="keywords" content="react native">
<meta property="og:type" content="article">
<meta property="og:title" content="react native 友盟统计 Android 端集成">
<meta property="og:url" content="https://jslinlink.gitee.io/blog/2018/08/31/reactnative友盟统计Android端集成/index.html">
<meta property="og:site_name" content="JsLin">
<meta property="og:description" content="ios 端 可参考：https://www.jianshu.com/p/879d28ee74e6趁热打铁吧，把刚才已经完成的友盟统计集成记录下  Android端集成：分下面几部： 步骤 sdk的集成 原生模块的配置 原生交互模块 RN端调用  sdk集成部分友盟sdk下载地址：https://developer.umeng.com/sdk?spm=a211g2.211692.0.0.4cc211">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/4731495-89ff77ebce62e012.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/4731495-5897f77444330125.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/4731495-8fedbad862a594ad.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/4731495-8a98b7b75da36ab7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/4731495-5fb02c5e754a4fc3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:updated_time" content="2018-08-31T08:23:05.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="react native 友盟统计 Android 端集成">
<meta name="twitter:description" content="ios 端 可参考：https://www.jianshu.com/p/879d28ee74e6趁热打铁吧，把刚才已经完成的友盟统计集成记录下  Android端集成：分下面几部： 步骤 sdk的集成 原生模块的配置 原生交互模块 RN端调用  sdk集成部分友盟sdk下载地址：https://developer.umeng.com/sdk?spm=a211g2.211692.0.0.4cc211">
<meta name="twitter:image" content="https://upload-images.jianshu.io/upload_images/4731495-89ff77ebce62e012.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">






  <link rel="canonical" href="https://jslinlink.gitee.io/blog/2018/08/31/reactnative友盟统计Android端集成/"/>



<script type="text/javascript" id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>react native 友盟统计 Android 端集成 | JsLin</title>
  






  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?d174915aad7705e258a97b2f8d3f1189";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style type="text/css">
    .use-motion .motion-element,
    .use-motion .brand,
    .use-motion .menu-item,
    .sidebar-inner,
    .use-motion .post-block,
    .use-motion .pagination,
    .use-motion .comments,
    .use-motion .post-header,
    .use-motion .post-body,
    .use-motion .collection-title { opacity: initial; }

    .use-motion .logo,
    .use-motion .site-title,
    .use-motion .site-subtitle {
      opacity: initial;
      top: initial;
    }

    .use-motion {
      .logo-line-before i { left: initial; }
      .logo-line-after i { right: initial; }
    }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">JsLin</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <p class="site-subtitle">记录点滴</p>
      
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">
    <a href="/blog/home" rel="section">
      <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-about">
    <a href="/blog/about" rel="section">
      <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">
    <a href="/blog/tags" rel="section">
      <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />标签</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">
    <a href="/blog/categories" rel="section">
      <i class="menu-item-icon fa fa-fw fa-th"></i> <br />分类</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">
    <a href="/blog/archives" rel="section">
      <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档</a>
  </li>

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />搜索</a>
        </li>
      
    </ul>
  

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://jslinlink.gitee.io/blog/blog/2018/08/31/reactnative友盟统计Android端集成/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="JsLin">
      <meta itemprop="description" content="我挥舞着键盘和本子，发誓要把世界写个明明白白！">
      <meta itemprop="image" content="http://upload.jianshu.io/users/upload_avatars/4731495/29f3b99a-7c9c-4d97-9353-90ede0196905%3FimageMogr2/auto-orient/strip%7CimageView2/1/w/240/h/240">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="JsLin">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">react native 友盟统计 Android 端集成
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2018-08-31 00:18:51 / 修改时间：16:23:05" itemprop="dateCreated datePublished" datetime="2018-08-31T00:18:51+08:00">2018-08-31</time>
            

            
              

              
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/RN集成SDK相关/" itemprop="url" rel="index"><span itemprop="name">RN集成SDK相关</span></a></span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/blog/2018/08/31/reactnative友盟统计Android端集成/#comments" itemprop="discussionUrl">
                
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2018/08/31/reactnative友盟统计Android端集成/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="post-meta-item-icon"
            >
            <i class="fa fa-eye"></i>
             阅读次数： 
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>ios 端 可参考：<a href="https://www.jianshu.com/p/879d28ee74e6" target="_blank" rel="noopener">https://www.jianshu.com/p/879d28ee74e6</a><br>趁热打铁吧，把刚才已经完成的友盟统计集成记录下  Android端集成：<br>分下面几部：</p>
<h3 id="步骤"><a href="#步骤" class="headerlink" title="步骤"></a>步骤</h3><ul>
<li>sdk的集成</li>
<li>原生模块的配置</li>
<li>原生交互模块</li>
<li>RN端调用</li>
</ul>
<h3 id="sdk集成部分"><a href="#sdk集成部分" class="headerlink" title="sdk集成部分"></a>sdk集成部分</h3><p>友盟sdk下载地址：<br><a href="https://developer.umeng.com/sdk?spm=a211g2.211692.0.0.4cc21183f5dYjU" target="_blank" rel="noopener">https://developer.umeng.com/sdk?spm=a211g2.211692.0.0.4cc21183f5dYjU</a><br>sdk集成相关文档：<br><a href="https://developer.umeng.com/docs/66632/detail/68337" target="_blank" rel="noopener">https://developer.umeng.com/docs/66632/detail/68337</a></p>
<p>这里如果嫌官方文档太乱的话可以参考下 我这里的手动集成：<br>1.首先把 下载的sdk<br>umeng-analytics-7.5.3.jar<br>umeng-common-1.5.3.jar<br>放到工程目录下的libs文件夹下，thirdparties文件下的可能和混淆加密有关，这里按需使用吧，我这里没有。<br><img src="https://upload-images.jianshu.io/upload_images/4731495-89ff77ebce62e012.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/4731495-5897f77444330125.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>把架包添加到工程中<br><img src="https://upload-images.jianshu.io/upload_images/4731495-8fedbad862a594ad.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">dependencies &#123;</span><br><span class="line">    compile files(&apos;libs/umeng-analytics-7.5.3.jar&apos;)</span><br><span class="line">    compile files(&apos;libs/umeng-common-1.5.3.jar&apos;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>到这里Android端sdk已经集成了。</p>
<h2 id="android端配置"><a href="#android端配置" class="headerlink" title="android端配置"></a>android端配置</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">&lt;manifest -- 中</span><br><span class="line">&lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot;/&gt;</span><br><span class="line">&lt;uses-permission android:name=&quot;android.permission.ACCESS_WIFI_STATE&quot;/&gt;</span><br><span class="line">&lt;uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot;/&gt;</span><br><span class="line">&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;</span><br><span class="line"></span><br><span class="line"> &lt;application --- 中 </span><br><span class="line">  &lt;!--友盟 统计--&gt;</span><br><span class="line">        &lt;meta-data</span><br><span class="line">            android:name=&quot;UMENG_APPKEY&quot;</span><br><span class="line">            android:value=&quot;5b863efe8f4a9d1b8b00010b&quot; &gt;</span><br><span class="line">        &lt;/meta-data&gt;</span><br><span class="line">        &lt;meta-data android:value=&quot;Channel ID&quot; android:name=&quot;UMENG_CHANNEL&quot;/&gt;</span><br></pre></td></tr></table></figure>
<h2 id="交互模块"><a href="#交互模块" class="headerlink" title="交互模块"></a>交互模块</h2><p>接下来把官网下载下来的 交互模块放到工程中   <a href="https://developer.umeng.com/sdk/reactnative" target="_blank" rel="noopener">https://developer.umeng.com/sdk/reactnative</a><br>注意这里下载下来的并不是sdk 而是 一些交互类<br>DplusReactPackage.java<br>RNUMConfigure.java<br>AnalyticsModule.java<br>这三个java交互文件缺一不可哦。<br><img src="https://upload-images.jianshu.io/upload_images/4731495-8a98b7b75da36ab7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="
"></p>
<p>之后，就是把相关 java代码，改下包路径 按照错误提示更改就行了</p>
<p>比如： package com.rent.UMTJ;<br>缺少类的 导入相关类即可。<br>交互类 写完之后，在MainApplication中实例化一下<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">@Override</span><br><span class="line">   protected List&lt;ReactPackage&gt; getPackages() &#123;</span><br><span class="line">     return Arrays.&lt;ReactPackage&gt;asList(</span><br><span class="line">         new MainReactPackage(),</span><br><span class="line">      </span><br><span class="line">           new DplusReactPackage(),</span><br><span class="line">      </span><br><span class="line">     );</span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">@Override</span><br><span class="line"> public void onCreate() &#123;</span><br><span class="line">   super.onCreate();</span><br><span class="line">   SoLoader.init(this, /* native exopackage */ false);</span><br><span class="line">   UMConfigure.setLogEnabled(true);</span><br><span class="line">   //初始化组件化基础库, 统计SDK/推送SDK/分享SDK都必须调用此初始化接口</span><br><span class="line">   RNUMConfigure.init(this, &quot;[这里输入自己创建应用时候的appkey]&quot;, &quot;UMENG_CHANNEL&quot;, UMConfigure.DEVICE_TYPE_PHONE,</span><br><span class="line">           &quot;&quot;);</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure></p>
<p>在MainActivity中也要初始化操作<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">@Override</span><br><span class="line">   protected void onCreate(Bundle savedInstanceState) &#123;</span><br><span class="line">    </span><br><span class="line">       MobclickAgent.setSessionContinueMillis(1000);   //设置统计的场景，以及发送间隔：</span><br><span class="line">       MobclickAgent.setScenarioType(this, MobclickAgent.EScenarioType.E_DUM_NORMAL);</span><br><span class="line">       super.onCreate(savedInstanceState);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">   &#125;</span><br><span class="line"> @Override</span><br><span class="line">   public void onResume() &#123;   //友盟统计初始化</span><br><span class="line">       super.onResume();</span><br><span class="line">       MobclickAgent.onResume(this);</span><br><span class="line">   &#125;</span><br><span class="line">   @Override</span><br><span class="line">   protected void onPause() &#123; //友盟统计初始化</span><br><span class="line">       super.onPause();</span><br><span class="line">       MobclickAgent.onPause(this);</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure></p>
<p>ok基本上按照步骤走的话，都很顺利，到这里就可以RN端调用了。</p>
<h2 id="RN端调用"><a href="#RN端调用" class="headerlink" title="RN端调用"></a>RN端调用</h2><p>这里封装了一下 Umtj.js 可作为参考<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">import &#123; NativeModules &#125; from &apos;react-native&apos;;</span><br><span class="line">const UMTJ = NativeModules.UMAnalyticsModule;</span><br><span class="line">export const onPageStart = pageName =&gt; &#123;</span><br><span class="line">  //用于统计单个自定义页面的起始和onPageEnd同时使用，不可单独使用</span><br><span class="line">  return UMTJ.onPageStart(pageName);</span><br><span class="line">&#125;;</span><br><span class="line">export const onPageEnd = pageName =&gt; &#123;</span><br><span class="line">  //用于统计单个Activity页面结束时间</span><br><span class="line">  return UMTJ.onPageEnd(pageName);</span><br><span class="line">&#125;;</span><br><span class="line">export const onEvent = eventId =&gt; &#123;</span><br><span class="line">  //用于统计自定义事件的发生次数</span><br><span class="line"></span><br><span class="line">  return UMTJ.onEvent(eventId);</span><br><span class="line">&#125;;</span><br><span class="line">export const onEventWithLable = (eventId, label) =&gt; &#123;</span><br><span class="line">  //用于统计自定义事件的发生次数 可传参数进去</span><br><span class="line"></span><br><span class="line">  return UMTJ.onEventWithLable(eventId, label);</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure></p>
<p>调用原生模块<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">import &#123;</span><br><span class="line">  onEvent,</span><br><span class="line">  onEventWithLable,</span><br><span class="line">  onPageStart,</span><br><span class="line">  onPageEnd,</span><br><span class="line">&#125; from &apos;../utils/natives/Umtj&apos;;</span><br><span class="line"></span><br><span class="line">//比如这里是个点击事件</span><br><span class="line"></span><br><span class="line">click=()=&gt;&#123;</span><br><span class="line"> onEvent(&apos;regist&apos;);</span><br><span class="line"> onEventWithLable(&apos;regist&apos;, &apos;注册登录成功&apos;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>这里的“regist”是我们在 友盟后台自定义的 埋点值，可以进行手动埋点 用来统计用户一些行为操作，方便产品运营吧。<br><img src="https://upload-images.jianshu.io/upload_images/4731495-5fb02c5e754a4fc3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>ios 端 可参考：<a href="https://www.jianshu.com/p/879d28ee74e6" target="_blank" rel="noopener">https://www.jianshu.com/p/879d28ee74e6</a></p>

      
    </div>

    

    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/react-native/" rel="tag"># react native</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2018/08/31/react-native-友盟统计-IOS-端集成/" rel="prev" title="react native 友盟统计 IOS 端集成">
                react native 友盟统计 IOS 端集成 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  
    <div class="comments" id="comments">
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="http://upload.jianshu.io/users/upload_avatars/4731495/29f3b99a-7c9c-4d97-9353-90ede0196905%3FimageMogr2/auto-orient/strip%7CimageView2/1/w/240/h/240"
                alt="JsLin" />
            
              <p class="site-author-name" itemprop="name">JsLin</p>
              <p class="site-description motion-element" itemprop="description">我挥舞着键盘和本子，发誓要把世界写个明明白白！</p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/blog/archives">
                
                    <span class="site-state-item-count">11</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/blog/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">4</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/blog/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">6</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  <a href="https://github.com/JslinSir" target="_blank" title="GitHub"><i class="fa fa-fw fa-github"></i>GitHub</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://blog.csdn.net/qq_34792916" target="_blank" title="CSDN"><i class="fa fa-fw fa-rotate-right"></i>CSDN</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://www.jianshu.com/u/fdebcd2b0fc3" target="_blank" title="简书"><i class="fa fa-fw fa-book"></i>简书</a>
                  
                </span>
              
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://reactnative.cn/" title="react native" target="_blank">react native</a>
                  </li>
                
              </ul>
            </div>
          

          
            
          
          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#步骤"><span class="nav-number">1.</span> <span class="nav-text">步骤</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#sdk集成部分"><span class="nav-number">2.</span> <span class="nav-text">sdk集成部分</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#android端配置"><span class="nav-number"></span> <span class="nav-text">android端配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#交互模块"><span class="nav-number"></span> <span class="nav-text">交互模块</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#RN端调用"><span class="nav-number"></span> <span class="nav-text">RN端调用</span></a></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">JsLin</span>

  

  
</div>











        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv" title="总访客量">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
    </span>
  

  
    <span class="site-pv" title="总访问量">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
    </span>
  
</div>









        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    
	
    

    
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=6.4.0"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=6.4.0"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=6.4.0"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=6.4.0"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=6.4.0"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=6.4.0"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=6.4.0"></script>



  

  
    <script id="dsq-count-scr" src="https://.disqus.com/count.js" async></script>
  

  
    <script type="text/javascript">
      var disqus_config = function () {
        this.page.url = 'https://jslinlink.gitee.io/blog/2018/08/31/reactnative友盟统计Android端集成/';
        this.page.identifier = '2018/08/31/reactnative友盟统计Android端集成/';
        this.page.title = 'react native 友盟统计 Android 端集成';
        };
      function loadComments () {
        var d = document, s = d.createElement('script');
        s.src = 'https://.disqus.com/embed.js';
        s.setAttribute('data-timestamp', '' + +new Date());
        (d.head || d.body).appendChild(s);
      }
      
        loadComments();
      
    </script>
  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  










  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/blog/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  

  
  

  

  

  

  

  

</body>
</html>
